<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>配置管理-(管理员/主播)</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.3.0/video-js.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.3.0/video.min.js"></script>

    <style>

        *
        {
            box-sizing: border-box;
        }
        body,
        html {
            margin: 0px auto;
            padding: 0;
            font-size: 14px;
            color: #555;
        }

        .vjs-poster {
            background-size: cover;
        }

        .m-input
        {
            line-height: 40px;
            height: 40px;
            padding: 6px 10px;
            border:1px lightseagreen solid;
        
        }

        .m-input-valid
        {
            border:1px orangered solid;
        }

        .m-btn
        {
            line-height: 40px;
            height: 40px;
            border:1px lightseagreen solid;
            background-color: lightseagreen;
            color: white;
        }

         .m-btn.m-btn-gray
        {
            line-height: 40px;
            height: 40px;
            border:1px lightgray solid;
            background-color: lightgray;
            color: #555;
        }

        .m-btn.active
        {
            background-color:teal;
            border:1px teal solid;
            color: white;
        }

        input
        {
            width: 100%;
            outline: none;
            outline-style: none;
        }

        .container
        {
            padding: 10px;
        }

        .mt_20
        {
            margin-top: 20px;
        }

        .mt_5
        {
            margin-top: 5px;
        }

        

        .info
        {
            line-height: 1em;
            padding: 10px;
            background-color: aliceblue;
            color: #555;
        }

        .none
        {
            display: none;
        }

        .config_textarea
        {
            margin-top: 5px;
            width: 100%;
            outline: none;
            outline-style: none;
        }

        .multi_btn_container .m-btn
        {
            width:48%;
            box-sizing: border-box;
        }

        .fl
        {
            float: left;
        }

         .fr
        {
            float: right;
        }

    </style>
</head>

<body>

    <div class="container">


        <input type="text" placeholder="请输入直播标识,纯英文或数字" class="m-input mt_20" id="videoKey" />
        <input type="password" placeholder="操作权限密码" class="m-input mt_20" id="secret" />
        <input type="button" value="设置默认直播标识" class=" m-btn mt_20 " id="setDefaultVideoKey" />
        <input type="button" value="清空默认直播标识" class=" m-btn mt_20 " id="clearDefaultVideoKey" />



        <div class="multi_btn_container">
            <input type="button" value="打开默认配置" class="fl m-btn  m-btn-gray mt_20" id="showConfig" />
            <input type="button" value="全量修改配置" class="fr m-btn mt_20" id="updateLiveConfigAll" />
        </div>

        <textarea class="config_textarea none" rows="30"></textarea>

        <input type="button" value="新窗口大屏查看默认配置" class=" m-btn  m-btn-gray mt_20" id="showConfigNewPage" onclick="window.location.href='qiniuConfig.json';" />


        <div class="info mt_20">
            <p>1.用途:用于更新直播配置文件.</p>
            <p>2.设置默认直播标识 有值则可直接播放</p>
            <p>3.清空默认直播标识 如不指定标识,则会退回入口</p>
        </div>

    </div>


    <script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
    <link rel="stylesheet" href="plugins/layer_mobile/need/layer.css" />
    <script src="plugins/layer_mobile/layer.js"></script>

    <script>
        $(function () {
            $('.m-btn').on("touchstart", function () {
                $(this).addClass("active");
            });

            $('.m-btn').on("touchend", function () {
                $(this).removeClass("active");
            })

            $('#setDefaultVideoKey').on('click', function () {
                SetVideoKey(0);
            });


            $('#clearDefaultVideoKey').on('click', function () {
                SetVideoKey(1);
            });


            function SetVideoKey(type) {
                type = type || 0; // 0改  1表

                var videoKey = $("#videoKey").val() || "";
                var secret = $("#secret").val() || "";

                if (type == 1) {
                    videoKey = '';
                } else {

                }


                if (type == 0 && videoKey == "") {
                    $("#videoKey").addClass('m-input-valid');
                    layer.open({
                        content: '请输入直播标识',
                        skin: 'msg',
                        time: 1 //2秒后自动关闭
                    });
                    return false;
                }



                if (secret == "") {
                    $("#secret").addClass('m-input-valid');
                    layer.open({
                        content: '请输入操作权限密码',
                        skin: 'msg',
                        time: 1 //2秒后自动关闭
                    });
                    return false;
                }

                layer.open({
                    content: '您确定要更新直播配置？',
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        $.get('updateLiveConfig/videoKey/' + ((type == 1) ? "-99" : videoKey) +
                            '?secret=' + secret,
                            function (remoteData) {
                                layer.open({
                                    content: remoteData.msg,
                                    skin: 'msg',
                                    time: 2 //2秒后自动关闭
                                });
                                remoteData.success && setTimeout(function () {
                                    $("#videoKey").val('');
                                    $("#secret").val('');
                                }, 1000);


                            });
                        layer.close(index);
                    }
                });
            }


            $("#showConfig").on('click', function () {
                console.log("去获取");
                var secret = $("#secret").val() || "";

                if (secret == "") {
                    $("#secret").addClass('m-input-valid');
                    layer.open({
                        content: '请输入操作权限密码',
                        skin: 'msg',
                        time: 1 //2秒后自动关闭
                    });
                    return false;
                }
                $(".config_textarea").removeClass('none');
                $.getJSON('qiniuConfig.json', function (remoteData) {
                    $(".config_textarea").html(JSON.stringify(remoteData, null, 4));
                });
            });

            $("#updateLiveConfigAll").on('click', function () {
                console.log("去保存");
                var secret = $("#secret").val() || "";


                if (secret == "") {
                    $("#secret").addClass('m-input-valid');
                    layer.open({
                        content: '请输入操作权限密码',
                        skin: 'msg',
                        time: 1 //2秒后自动关闭
                    });
                    return false;
                }


                if ($('.config_textarea').hasClass('none')) {
                    layer.open({
                        content: '请先打开默认配置',
                        skin: 'msg',
                        time: 1 //2秒后自动关闭
                    });
                    return false;
                }





                layer.open({
                    content: '您确定要全量更新直播配置？',
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        $.post('updateLiveConfig/all/' + '?secret=' + secret, JSON.parse($(
                                ".config_textarea").val()),
                            function (result) {
                                layer.open({
                                    content: result.msg,
                                    skin: 'msg',
                                    time: 2 //2秒后自动关闭
                                });
                                result.success && setTimeout(function () {
                                    $(".config_textarea").addClass(
                                        'none');
                                    $(".config_textarea").html('');
                                }, 1000);

                            });
                        layer.close(index);
                    }
                });



            });



            $('.m-input').on('focus', function () {
                $(this).removeClass('m-input-valid');
            });




        });
    </script>
</body>

</html>